<template>
<div class='grid' style="height:100%;">
        <el-table v-if="isDisplay === true"
        :default-sort="{ prop: minorSortPSDEF, order: Object.is(minorSortDir, 'ASC') ? 'ascending' : Object.is(minorSortDir, 'DESC') ? 'descending' : '' }"  
        @sort-change="onSortChange($event)"  
        :border="isDragendCol"
        :height="isEnablePagingBar && items.length > 0 ? 'calc(100% - 36px)' : '100%'"  
        :highlight-current-row ="isSingleSelect"
        :row-class-name="getRowClassName"
        @row-click="rowClick($event)"  
        @select-all="selectAll($event)"  
        @select="select($event)"  
        @row-class-name="onRowClassName($event)"  
        @row-dblclick="rowDBLClick($event)"  
        ref='multipleTable' :data="items" :show-header="!isHideHeader">
            <template slot="empty">
                无数据 
                <span class="quick-toolbar">
                </span>
            </template>
            <template v-if="!isSingleSelect">
                <el-table-column align="center" type='selection' :width="checkboxColWidth"></el-table-column>
            </template>
            <template v-if="getColumnState('contractcode')">
                <el-table-column show-overflow-tooltip :prop="'contractcode'" :label="$t('entities.pfcontract.main2_grid.columns.contractcode')" :width="120" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractcode}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('pfcontractname')">
                <el-table-column show-overflow-tooltip :prop="'pfcontractname'" :label="$t('entities.pfcontract.main2_grid.columns.pfcontractname')" :width="180" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <app-column-link deKeyField='pfcontract' :context="JSON.parse(JSON.stringify(context))" :viewparams="JSON.parse(JSON.stringify(viewparams))" :data="row" :linkview="{viewname: 'pfcontractedit-view9', height: 0,width: 0,title: $t('entities.pfcontract.views.editview9.title'),placement: 'DRAWER_TOP', isRedirectView: false,deResParameters: [
            ]
            ,parameters: [
            { pathName: 'pfcontracts', parameterName: 'pfcontract' },
            { pathName: 'editview9', parameterName: 'editview9' }
            ]}" valueitem="srfkey">
                            <span>{{row.pfcontractname}}</span>
                        </app-column-link >
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractno')">
                <el-table-column show-overflow-tooltip :prop="'contractno'" :label="$t('entities.pfcontract.main2_grid.columns.contractno')" :width="140" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractno}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contracttypeid')">
                <el-table-column show-overflow-tooltip :prop="'contracttypeid'" :label="$t('entities.pfcontract.main2_grid.columns.contracttypeid')" :width="150" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <template >
            <codelist :value="row.contracttypeid" tag='EMCONTRACTTYPEID' codelistType='STATIC' ></codelist>
                        </template>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('sdate')">
                <el-table-column show-overflow-tooltip :prop="'sdate'" :label="$t('entities.pfcontract.main2_grid.columns.sdate')" :width="130" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <app-format-data format="YYYY-MM-DD" :data="row.sdate"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractgroup')">
                <el-table-column show-overflow-tooltip :prop="'contractgroup'" :label="$t('entities.pfcontract.main2_grid.columns.contractgroup')" :width="130" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <template >
            <codelist :value="row.contractgroup" tag='YesNo' codelistType='STATIC' ></codelist>
                        </template>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractobjgroup')">
                <el-table-column show-overflow-tooltip :prop="'contractobjgroup'" :label="$t('entities.pfcontract.main2_grid.columns.contractobjgroup')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <template >
            <codelist :value="row.contractobjgroup" tag='EMCONTRACTOBJGROUP' codelistType='STATIC' ></codelist>
                        </template>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('checkstandard')">
                <el-table-column show-overflow-tooltip :prop="'checkstandard'" :label="$t('entities.pfcontract.main2_grid.columns.checkstandard')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.checkstandard}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('description')">
                <el-table-column show-overflow-tooltip :prop="'description'" :label="$t('entities.pfcontract.main2_grid.columns.description')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.description}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('declaration')">
                <el-table-column show-overflow-tooltip :prop="'declaration'" :label="$t('entities.pfcontract.main2_grid.columns.declaration')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.declaration}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('rorgid')">
                <el-table-column show-overflow-tooltip :prop="'rorgid'" :label="$t('entities.pfcontract.main2_grid.columns.rorgid')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.rorgid}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('performrecord')">
                <el-table-column show-overflow-tooltip :prop="'performrecord'" :label="$t('entities.pfcontract.main2_grid.columns.performrecord')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.performrecord}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('changedesc')">
                <el-table-column show-overflow-tooltip :prop="'changedesc'" :label="$t('entities.pfcontract.main2_grid.columns.changedesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.changedesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('paydesc')">
                <el-table-column show-overflow-tooltip :prop="'paydesc'" :label="$t('entities.pfcontract.main2_grid.columns.paydesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.paydesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('payamount')">
                <el-table-column show-overflow-tooltip :prop="'payamount'" :label="$t('entities.pfcontract.main2_grid.columns.payamount')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                            <app-format-data dataType="CURRENCY" precision="0" :data="row.payamount"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('payreason')">
                <el-table-column show-overflow-tooltip :prop="'payreason'" :label="$t('entities.pfcontract.main2_grid.columns.payreason')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.payreason}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('recvdoc')">
                <el-table-column show-overflow-tooltip :prop="'recvdoc'" :label="$t('entities.pfcontract.main2_grid.columns.recvdoc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.recvdoc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('changecontent')">
                <el-table-column show-overflow-tooltip :prop="'changecontent'" :label="$t('entities.pfcontract.main2_grid.columns.changecontent')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.changecontent}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('performstate')">
                <el-table-column show-overflow-tooltip :prop="'performstate'" :label="$t('entities.pfcontract.main2_grid.columns.performstate')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <template >
            <codelist :value="row.performstate" tag='EMPERFORMSTATE' codelistType='STATIC' ></codelist>
                        </template>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractdesc')">
                <el-table-column show-overflow-tooltip :prop="'contractdesc'" :label="$t('entities.pfcontract.main2_grid.columns.contractdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractdoc')">
                <el-table-column show-overflow-tooltip :prop="'contractdoc'" :label="$t('entities.pfcontract.main2_grid.columns.contractdoc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractdoc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('apprdate')">
                <el-table-column show-overflow-tooltip :prop="'apprdate'" :label="$t('entities.pfcontract.main2_grid.columns.apprdate')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <app-format-data format="YYYY-MM-DD hh:mm:ss" :data="row.apprdate"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('apprstate')">
                <el-table-column show-overflow-tooltip :prop="'apprstate'" :label="$t('entities.pfcontract.main2_grid.columns.apprstate')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <template >
            <codelist :value="row.apprstate" tag='EMAPPRSTATE' codelistType='STATIC' ></codelist>
                        </template>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('apprdesc')">
                <el-table-column show-overflow-tooltip :prop="'apprdesc'" :label="$t('entities.pfcontract.main2_grid.columns.apprdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.apprdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractobjid')">
                <el-table-column show-overflow-tooltip :prop="'contractobjid'" :label="$t('entities.pfcontract.main2_grid.columns.contractobjid')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractobjid}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('certdesc')">
                <el-table-column show-overflow-tooltip :prop="'certdesc'" :label="$t('entities.pfcontract.main2_grid.columns.certdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.certdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('licdesc')">
                <el-table-column show-overflow-tooltip :prop="'licdesc'" :label="$t('entities.pfcontract.main2_grid.columns.licdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.licdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('attdesc')">
                <el-table-column show-overflow-tooltip :prop="'attdesc'" :label="$t('entities.pfcontract.main2_grid.columns.attdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.attdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('docdesc')">
                <el-table-column show-overflow-tooltip :prop="'docdesc'" :label="$t('entities.pfcontract.main2_grid.columns.docdesc')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.docdesc}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('attention')">
                <el-table-column show-overflow-tooltip :prop="'attention'" :label="$t('entities.pfcontract.main2_grid.columns.attention')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.attention}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contracttender')">
                <el-table-column show-overflow-tooltip :prop="'contracttender'" :label="$t('entities.pfcontract.main2_grid.columns.contracttender')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contracttender}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('performway')">
                <el-table-column show-overflow-tooltip :prop="'performway'" :label="$t('entities.pfcontract.main2_grid.columns.performway')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.performway}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractnum')">
                <el-table-column show-overflow-tooltip :prop="'contractnum'" :label="$t('entities.pfcontract.main2_grid.columns.contractnum')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractnum}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractdate')">
                <el-table-column show-overflow-tooltip :prop="'contractdate'" :label="$t('entities.pfcontract.main2_grid.columns.contractdate')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <app-format-data format="YYYY-MM-DD" :data="row.contractdate"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractprice')">
                <el-table-column show-overflow-tooltip :prop="'contractprice'" :label="$t('entities.pfcontract.main2_grid.columns.contractprice')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                            <app-format-data dataType="CURRENCY" precision="0" :data="row.contractprice"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('performline')">
                <el-table-column show-overflow-tooltip :prop="'performline'" :label="$t('entities.pfcontract.main2_grid.columns.performline')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.performline}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('contractqa')">
                <el-table-column show-overflow-tooltip :prop="'contractqa'" :label="$t('entities.pfcontract.main2_grid.columns.contractqa')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.contractqa}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('paycnt')">
                <el-table-column show-overflow-tooltip :prop="'paycnt'" :label="$t('entities.pfcontract.main2_grid.columns.paycnt')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.paycnt}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('amount')">
                <el-table-column show-overflow-tooltip :prop="'amount'" :label="$t('entities.pfcontract.main2_grid.columns.amount')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                            <app-format-data dataType="CURRENCY" precision="0" :data="row.amount"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('peramount')">
                <el-table-column show-overflow-tooltip :prop="'peramount'" :label="$t('entities.pfcontract.main2_grid.columns.peramount')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                            <app-format-data dataType="CURRENCY" precision="0" :data="row.peramount"></app-format-data>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('performplace')">
                <el-table-column show-overflow-tooltip :prop="'performplace'" :label="$t('entities.pfcontract.main2_grid.columns.performplace')" :width="100" :align="'left'" :sortable="'custom'">
                    <template v-slot="{row,column}">
                        <span>{{row.performplace}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="adaptiveState">
                <el-table-column></el-table-column>
            </template>
    </el-table>
    <row class='grid-pagination' v-show="items.length > 0">
        <page class='pull-right' @on-change="pageOnChange($event)" 
            @on-page-size-change="onPageSizeChange($event)"
            :transfer="true" :total="totalrow"
            show-sizer :current="curPage" :page-size="limit"
            :page-size-opts="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]" show-elevator show-total>
            <span>
                <span class="page-column">
                    <poptip transfer placement="top-start">
                        <i-button icon="md-menu">{{$t('app.gridpage.choicecolumns')}}</i-button>
                        <div slot="content">
                            <template v-for="col in allColumns">
                                <div :key="col.name"><el-checkbox v-model="col.show" @change="onColChange()">{{$t(col.langtag)}}</el-checkbox></div>
                            </template>
                        </div>
                    </poptip>
                </span>
                <span v-if="selections.length > 0" class="batch-toolbar">
                </span>
                <span class="page-button"><i-button icon="md-refresh" :title="$t('app.gridpage.refresh')" @click="pageRefresh()"></i-button></span>&nbsp;
                <span>
                    {{$t('app.gridpage.show')}}&nbsp;
                    <span>
                        <template v-if="items.length === 1">
                        1
                        </template>
                        <template v-else>
                            <span>{{(curPage - 1) * limit + 1}}&nbsp;-&nbsp;{{totalrow > curPage * limit ? curPage * limit : totalrow}}</span>
                        </template>
                    </span>&nbsp;
                    {{$t('app.gridpage.records')}}，{{$t('app.gridpage.totle')}}&nbsp;{{totalrow}}&nbsp;{{$t('app.gridpage.records')}}
                </span>
            </span>
        </page>
    </row>
</div>
</template>
<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util } from '@/utils';
import PFContractService from '@/service/pfcontract/pfcontract-service';
import Main2Service from './main2-grid-service';

import CodeListService from "@service/app/codelist-service";


@Component({
    components: {
      
    }
})
export default class Main2Base extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof Main2
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof Main2
     */
    @Prop() public context: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof Main2
     */
    @Prop() public viewparams: any;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof Main2
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
     * @memberof Main2
     */
    public getControlType(): string {
        return 'GRID'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof Main2
     */    
    public counterServiceArray:Array<any> = [];

    /**
     * 建构部件服务对象
     *
     * @type {Main2Service}
     * @memberof Main2
     */
    public service: Main2Service = new Main2Service({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {PFContractService}
     * @memberof Main2
     */
    public appEntityService: PFContractService = new PFContractService({ $store: this.$store });
    


    /**
     * 关闭视图
     *
     * @param {any} args
     * @memberof Main2
     */
    public closeView(args: any): void {
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
     * @memberof Main2
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
     * @memberof Main2
     */  
    public codeListService:CodeListService = new CodeListService({ $store: this.$store });

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof Main2
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof Main2
     */
    public getData(): any {
        return this.selections[0];
    }

    /**
     * 打开新建数据视图
     *
     * @type {any}
     * @memberof Main2
     */
    @Prop() public newdata: any;
    /**
     * 打开编辑数据视图
     *
     * @type {any}
     * @memberof Main2
     */
    @Prop() public opendata: any;

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof Main2
     */
    @Prop({ default: true }) public showBusyIndicator?: boolean;

    /**
     * 部件行为--update
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public updateAction!: string;
    
    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public fetchAction!: string;
    
    /**
     * 部件行为--remove
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public removeAction!: string;
    
    /**
     * 部件行为--load
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public loadAction!: string;
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public loaddraftAction!: string;
    
    /**
     * 部件行为--create
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public createAction!: string;

    /**
     * 当前页
     *
     * @type {number}
     * @memberof Main2
     */
    public curPage: number = 1;

    /**
     * 数据
     *
     * @type {any[]}
     * @memberof Main2
     */
    public items: any[] = [];

    /**
     * 是否支持分页
     *
     * @type {boolean}
     * @memberof Main2
     */
    public isEnablePagingBar: boolean = true;

    /**
     * 是否禁用排序
     *
     * @type {boolean}
     * @memberof Main2
     */
    public isNoSort: boolean = false;

    /**
     * 排序方向
     *
     * @type {string}
     * @memberof Main2
     */
    public minorSortDir: string = '';

    /**
     * 排序字段
     *
     * @type {string}
     * @memberof Main2
     */
    public minorSortPSDEF: string = '';

    /**
     * 分页条数
     *
     * @type {number}
     * @memberof Main2
     */
    public limit: number = 20;

    /**
     * 是否显示标题
     *
     * @type {boolean}
     * @memberof Main2
     */
    public isHideHeader: boolean = false;

    /**
     * 是否默认选中第一条数据
     *
     * @type {boolean}
     * @memberof Main2
     */
    @Prop({ default: false }) public isSelectFirstDefault!: boolean;

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof Main2
     */
    @Prop() public isSingleSelect?: boolean;

    /**
     * 选中数据字符串
     *
     * @type {string}
     * @memberof Main2
     */
    @Prop() public selectedData?: string;

    /**
     * 选中值变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof MainTree
     */
    @Watch('selectedData')
    public onValueChange(newVal: any, oldVal: any) {
        this.selections = [];
        if(this.selectedData){
            const refs: any = this.$refs;
            if (refs.multipleTable) {
                refs.multipleTable.clearSelection();
                JSON.parse(this.selectedData).forEach((selection:any)=>{
                    let selectedItem = this.items.find((item:any)=>{
                        return Object.is(item.srfkey, selection.srfkey);
                    });
                    if(selectedItem){
                        this.rowClick(selectedItem);
                    }
                });
            }
        }
    }

    /**
     * 表格行数据默认激活模式
     * 0 不激活
     * 1 单击激活
     * 2 双击激活
     *
     * @type {(number | 0 | 1 | 2)}
     * @memberof Main2
     */
    @Prop({default: 2}) public gridRowActiveMode!: number;

    /**
     * 是否开启行编辑
     *
     * @type {boolean}
     * @memberof Main2
     */
    @Prop({default: false}) public isOpenEdit!: boolean;

    /**
     * 实际是否开启行编辑
     *
     * @type {boolean}
     * @memberof Main2
     */
    public actualIsOpenEdit: boolean = this.isOpenEdit;

    /**
     * 总条数
     *
     * @type {number}
     * @memberof Main2
     */
    public totalrow: number = 0;

    /**
     * 选中行数据
     *
     * @type {any[]}
     * @memberof Main
     */
    public selections: any[] = [];

    /**
     * 拦截行选中
     *
     * @type {boolean}
     * @memberof Main
     */
    public stopRowClick: boolean = false;




    /**
     * 表格是否显示
     *
     * @type {boolean}
     * @memberof Main2
     */
    public isDisplay:boolean = true;

    /**
     * 部件刷新
     *
     * @param {any[]} args
     * @memberof Main2
     */
    public refresh(args: any[]): void {
        this.load();
    }

    /**
    * 选项框列宽
    *
    * @type {number}
    * @memberof AppIndex
    */
    protected checkboxColWidth: number = 34;

    /**
     * 是否允许拖动列宽
     *
     * @type {boolean}
     * @memberof AppEmbedPicker
     */
    public isDragendCol: boolean = false;

    /**
     * 所有列成员
     *
     * @type {any[]}
     * @memberof Main2
     */
    public allColumns: any[] = [
        {
            name: 'contractcode',
            label: '合同代码',
            langtag: 'entities.pfcontract.main2_grid.columns.contractcode',
            show: true,
            util: 'PX'
        },
        {
            name: 'pfcontractname',
            label: '合同名称',
            langtag: 'entities.pfcontract.main2_grid.columns.pfcontractname',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractno',
            label: '合同序列号',
            langtag: 'entities.pfcontract.main2_grid.columns.contractno',
            show: true,
            util: 'PX'
        },
        {
            name: 'contracttypeid',
            label: '合同类型',
            langtag: 'entities.pfcontract.main2_grid.columns.contracttypeid',
            show: true,
            util: 'PX'
        },
        {
            name: 'sdate',
            label: '上报时间',
            langtag: 'entities.pfcontract.main2_grid.columns.sdate',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractgroup',
            label: '乙方',
            langtag: 'entities.pfcontract.main2_grid.columns.contractgroup',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractobjgroup',
            label: '合同对方分组',
            langtag: 'entities.pfcontract.main2_grid.columns.contractobjgroup',
            show: true,
            util: 'PX'
        },
        {
            name: 'checkstandard',
            label: '验收标准',
            langtag: 'entities.pfcontract.main2_grid.columns.checkstandard',
            show: true,
            util: 'PX'
        },
        {
            name: 'description',
            label: '描述',
            langtag: 'entities.pfcontract.main2_grid.columns.description',
            show: true,
            util: 'PX'
        },
        {
            name: 'declaration',
            label: '其它事项说明',
            langtag: 'entities.pfcontract.main2_grid.columns.declaration',
            show: true,
            util: 'PX'
        },
        {
            name: 'rorgid',
            label: '盖章单位',
            langtag: 'entities.pfcontract.main2_grid.columns.rorgid',
            show: true,
            util: 'PX'
        },
        {
            name: 'performrecord',
            label: '合同履约记录',
            langtag: 'entities.pfcontract.main2_grid.columns.performrecord',
            show: true,
            util: 'PX'
        },
        {
            name: 'changedesc',
            label: '调整说明',
            langtag: 'entities.pfcontract.main2_grid.columns.changedesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'paydesc',
            label: '合同付款情况',
            langtag: 'entities.pfcontract.main2_grid.columns.paydesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'payamount',
            label: '已付金额(万元)',
            langtag: 'entities.pfcontract.main2_grid.columns.payamount',
            show: true,
            util: 'PX'
        },
        {
            name: 'payreason',
            label: '付款理由',
            langtag: 'entities.pfcontract.main2_grid.columns.payreason',
            show: true,
            util: 'PX'
        },
        {
            name: 'recvdoc',
            label: '收到资料名称',
            langtag: 'entities.pfcontract.main2_grid.columns.recvdoc',
            show: true,
            util: 'PX'
        },
        {
            name: 'changecontent',
            label: '变更内容',
            langtag: 'entities.pfcontract.main2_grid.columns.changecontent',
            show: true,
            util: 'PX'
        },
        {
            name: 'performstate',
            label: '履约情况',
            langtag: 'entities.pfcontract.main2_grid.columns.performstate',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractdesc',
            label: '备注',
            langtag: 'entities.pfcontract.main2_grid.columns.contractdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractdoc',
            label: '合同原件',
            langtag: 'entities.pfcontract.main2_grid.columns.contractdoc',
            show: true,
            util: 'PX'
        },
        {
            name: 'apprdate',
            label: '审批时间',
            langtag: 'entities.pfcontract.main2_grid.columns.apprdate',
            show: true,
            util: 'PX'
        },
        {
            name: 'apprstate',
            label: '审批状态',
            langtag: 'entities.pfcontract.main2_grid.columns.apprstate',
            show: true,
            util: 'PX'
        },
        {
            name: 'apprdesc',
            label: '审批备注',
            langtag: 'entities.pfcontract.main2_grid.columns.apprdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractobjid',
            label: '合同对方',
            langtag: 'entities.pfcontract.main2_grid.columns.contractobjid',
            show: true,
            util: 'PX'
        },
        {
            name: 'certdesc',
            label: '资质证书',
            langtag: 'entities.pfcontract.main2_grid.columns.certdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'licdesc',
            label: '许可证',
            langtag: 'entities.pfcontract.main2_grid.columns.licdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'attdesc',
            label: '附件名称',
            langtag: 'entities.pfcontract.main2_grid.columns.attdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'docdesc',
            label: '其他资料',
            langtag: 'entities.pfcontract.main2_grid.columns.docdesc',
            show: true,
            util: 'PX'
        },
        {
            name: 'attention',
            label: '需说明事项',
            langtag: 'entities.pfcontract.main2_grid.columns.attention',
            show: true,
            util: 'PX'
        },
        {
            name: 'contracttender',
            label: '合同标准',
            langtag: 'entities.pfcontract.main2_grid.columns.contracttender',
            show: true,
            util: 'PX'
        },
        {
            name: 'performway',
            label: '履行方式',
            langtag: 'entities.pfcontract.main2_grid.columns.performway',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractnum',
            label: '合同数量',
            langtag: 'entities.pfcontract.main2_grid.columns.contractnum',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractdate',
            label: '订立日期',
            langtag: 'entities.pfcontract.main2_grid.columns.contractdate',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractprice',
            label: '合同单价(￥)',
            langtag: 'entities.pfcontract.main2_grid.columns.contractprice',
            show: true,
            util: 'PX'
        },
        {
            name: 'performline',
            label: '履行期限',
            langtag: 'entities.pfcontract.main2_grid.columns.performline',
            show: true,
            util: 'PX'
        },
        {
            name: 'contractqa',
            label: '合同质量',
            langtag: 'entities.pfcontract.main2_grid.columns.contractqa',
            show: true,
            util: 'PX'
        },
        {
            name: 'paycnt',
            label: '付款期数',
            langtag: 'entities.pfcontract.main2_grid.columns.paycnt',
            show: true,
            util: 'PX'
        },
        {
            name: 'amount',
            label: '价款(万元)',
            langtag: 'entities.pfcontract.main2_grid.columns.amount',
            show: true,
            util: 'PX'
        },
        {
            name: 'peramount',
            label: '每次付款数',
            langtag: 'entities.pfcontract.main2_grid.columns.peramount',
            show: true,
            util: 'PX'
        },
        {
            name: 'performplace',
            label: '履行地点',
            langtag: 'entities.pfcontract.main2_grid.columns.performplace',
            show: true,
            util: 'PX'
        },
    ]

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof Main2
     */
    public rules: any = {
        srfkey: [
             { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '合同标识 值不能为空', trigger: 'change' },
            { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '合同标识 值不能为空', trigger: 'blur' },
        ],
    }

    /**
     * 表格数据加载
     *
     * @param {*} [arg={}]
     * @memberof Main2
     */
    public load(opt: any = {}, pageReset: boolean = false): void {
        if(!this.fetchAction){
            this.$Notice.error({ title: '错误', desc: 'PFCONTRACTGridView视图表格fetchAction参数未配置' });
            return;
        }
        if(pageReset){
            this.curPage = 1;
        }
        const arg: any = {...opt};
        const page: any = {};
        if (this.isEnablePagingBar) {
            Object.assign(page, { page: this.curPage-1, size: this.limit });
        }
        // 设置排序
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
            const sort: string = this.minorSortPSDEF+","+this.minorSortDir;
            Object.assign(page, { sort: sort });
        }
        Object.assign(arg, page);
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
        let tempViewParams:any = parentdata.viewparams?parentdata.viewparams:{};
        Object.assign(tempViewParams,JSON.parse(JSON.stringify(this.viewparams)));
        Object.assign(arg,{viewparams:tempViewParams});
        const post: Promise<any> = this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
                if (response.errorMessage) {
                    this.$Notice.error({ title: '错误', desc: response.errorMessage });
                }
                return;
            }
            const data: any = response.data;
            this.totalrow = response.total;
            this.items = JSON.parse(JSON.stringify(data));
            // 清空selections
            this.selections = [];
            this.$emit('load', this.items);
            // 设置默认选中
            let _this = this;
            setTimeout(() => {
                if(_this.isSelectFirstDefault){
                  _this.rowClick(_this.items[0]);
                }
                if(_this.selectedData){
                    const refs: any = _this.$refs;
                    if (refs.multipleTable) {
                        refs.multipleTable.clearSelection();
                        JSON.parse(_this.selectedData).forEach((selection:any)=>{
                            let selectedItem = _this.items.find((item:any)=>{
                                return Object.is(item.srfkey, selection.srfkey);
                            });
                            if(selectedItem){
                                _this.rowClick(selectedItem);
                            }
                        });
                    }
                }
            }, 300);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: '错误', desc: response.errorMessage });
        });
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof Main2
     */
    public async remove(datas: any[]): Promise<any> {
        if(!this.removeAction){
            this.$Notice.error({ title: '错误', desc: 'PFCONTRACTGridView视图表格removeAction参数未配置' });
            return;
        }
        let _datas:any[] = [];
        datas.forEach((record: any, index: number) => {
            if (!record.srfkey) {
                this.items.some((val: any, num: number) =>{
                    if(JSON.stringify(val) == JSON.stringify(record)){
                        this.items.splice(num,1);
                        return true;
                    }
                }); 
            }else{
               _datas.push(datas[index]);
            }
        });
        if (_datas.length === 0) {
            return;
        }
        let dataInfo = '';
        _datas.forEach((record: any, index: number) => {
            let srfmajortext = record.pfcontractname;
            if (index < 5) {
                if (!Object.is(dataInfo, '')) {
                    dataInfo += '、';
                }
                dataInfo += srfmajortext;
            } else {
                return false;
            }
        });

        if (_datas.length < 5) {
            dataInfo = dataInfo + ' 共' + _datas.length + '条数据';
        } else {
            dataInfo = dataInfo + '...' + ' 共' + _datas.length + '条数据';
        }

        const removeData = () => {
            let keys: any[] = [];
            _datas.forEach((data: any) => {
                keys.push(data.srfkey);
            });
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction ;
            const context:any = JSON.parse(JSON.stringify(this.context));
            const post: Promise<any> = this.service.delete(_removeAction,Object.assign(context,{ pfcontract: keys.join(';') }),Object.assign({ pfcontract: keys.join(';') },{viewparams:this.viewparams}), this.showBusyIndicator);
            return new Promise((resolve: any, reject: any) => {
                post.then((response: any) => {
                    if (!response || response.status !== 200) {
                        this.$Notice.error({ title: '', desc: '删除数据失败,' + response.info });
                        return;
                    } else {
                        this.$Notice.success({ title: '', desc: '删除成功!' });
                    }
                    //删除items中已删除的项
                    console.log(this.items);
                    _datas.forEach((data: any) => {
                      this.items.some((item:any,index:number)=>{
                        if(Object.is(item.srfkey,data.srfkey)){
                          this.items.splice(index,1);
                                return true;
                            }
                        });
                    });
                    this.totalrow -= _datas.length;
                    this.$emit('remove', null);
                    this.selections = [];
                    resolve(response);
                }).catch((response: any) => {
                    if (response && response.status === 401) {
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        reject(response);
                        return;
                    }
                    reject(response);
                });
            });
        }

        dataInfo = dataInfo.replace(/[null]/g, '').replace(/[undefined]/g, '');
        this.$Modal.confirm({
            title: '警告',
            content: '确认要删除 ' + dataInfo + '，删除操作将不可恢复？',
            onOk: () => {
                removeData();
            },
            onCancel: () => { }
        });
        return removeData;
    }


    /**
     * 批量添加
     *
     * @param {*} [arg={}]
     * @memberof Main2
     */
    public addBatch(arg: any = {}): void {
        if(!this.fetchAction){
            this.$Notice.error({ title: '错误', desc: 'PFCONTRACTGridView视图表格fetchAction参数未配置' });
            return;
        }
        if(!arg){
            arg = {};
        }
        console.error("批量添加未实现");
    }

    /**
     * 数据导入
     *
     * @param {*} data
     * @memberof Main2
     */
     public importExcel(data:any ={}):void{
        //导入excel
        const importDataModel:any ={
        }
        if(Object.keys(importDataModel).length == 0){
            this.$Notice.warning({ 'title': (this.$t("app.utilview.warning") as string), 'desc': (this.$t("app.utilview.info") as string) });
            return;
        }
        const view:any ={
            viewname: 'app-data-upload',
            title: this.$t("app.utilview.importview"),
            width: 900,
            height: 700
        }
        let container: Subject<any> = this.$appmodal.openModal(view, JSON.parse(JSON.stringify(this.context)), importDataModel);
        container.subscribe((result: any) => {
          if(Object.is(result.ret,'OK')){
            this.refresh(result.datas);
          }
      });
    }


    /**
     * 数据导出
     *
     * @param {*} data
     * @memberof Main2
     */
    public exportExcel(data: any = {}): void {
        // 导出Excel
        const doExport = async (_data:any) => {
            const tHeader: Array<any> = [];
            const filterVal: Array<any> = [];
            this.allColumns.forEach((item: any) => {
              item.show && item.label ? tHeader.push(this.$t(item.langtag)) : "";
              item.show && item.name ? filterVal.push(item.name) : "";
            });
            const data = await this.formatExcelData(filterVal, _data);
            this.$export.exportExcel().then((excel:any)=>{
                excel.export_json_to_excel({
                  header: tHeader, //表头 必填
                  data, //具体数据 必填
                  filename: "合同表", //非必填
                  autoWidth: true, //非必填
                  bookType: "xlsx" //非必填
                });
            }); 
        };
        const page: any = {};
        // 设置page，size
        if (Object.is(data.type, 'maxRowCount')) {
            Object.assign(page, { page: 0, size: data.maxRowCount });
        } else if (Object.is(data.type, 'activatedPage')) {
            try {
                doExport(JSON.parse(JSON.stringify(this.items)));
            } catch (error) {
                console.error(error);
            }
            return;
        }
        // 设置排序
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
          const sort: string = this.minorSortPSDEF+","+this.minorSortDir;
            Object.assign(page, { sort: sort });
        }
        const arg: any = {};
        Object.assign(arg, page);
        // 获取query,搜索表单，viewparams等父数据
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
        const post: Promise<any> = this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response || response.status !== 200) {
                this.$Notice.error({ title: '', desc: '数据导出失败,' + response.info });
                return;
            }
            try {
                doExport(JSON.parse(JSON.stringify(response.data)));
            } catch (error) {
                console.error(error);
            }
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: '', desc: '数据导出失败' });
        });
    }


    /**
     * 导出数据格式化
     * 
     * @param {*} filterVal
     * @param {*} jsonData
     * @returns {[]}
     * @memberof Main2
     */
    public async formatExcelData(filterVal:any, jsonData:any) {
        let codelistColumns:Array<any> = [
          {
            name: 'contracttypeid',
            srfkey: 'EMCONTRACTTYPEID',
            codelistType : 'STATIC',
            renderMode: 'other',
            textSeparator: '、',
            valueSeparator: ',',
          },
          {
            name: 'contractgroup',
            srfkey: 'YesNo',
            codelistType : 'STATIC',
            renderMode: 'other',
            textSeparator: '、',
            valueSeparator: ',',
          },
          {
            name: 'contractobjgroup',
            srfkey: 'EMCONTRACTOBJGROUP',
            codelistType : 'STATIC',
            renderMode: 'other',
            textSeparator: '、',
            valueSeparator: ',',
          },
          {
            name: 'performstate',
            srfkey: 'EMPERFORMSTATE',
            codelistType : 'STATIC',
            renderMode: 'other',
            textSeparator: '、',
            valueSeparator: ',',
          },
          {
            name: 'apprstate',
            srfkey: 'EMAPPRSTATE',
            codelistType : 'STATIC',
            renderMode: 'other',
            textSeparator: '、',
            valueSeparator: ',',
          },
        ];
        let _this = this;
        for (const codelist of codelistColumns) {
          // 动态代码表处理
          if (Object.is(codelist.codelistType, "DYNAMIC")) {
              let items = await _this.codeListService.getItems(codelist.srfkey);
              jsonData.forEach((row:any)=>{
                  row[codelist.name] = _this.getCodelistValue(items, row[codelist.name], codelist);
              });
          // 静态处理
          } else if(Object.is(codelist.codelistType, "STATIC")){
              let items = await _this.$store.getters.getCodeListItems(codelist.srfkey);
              jsonData.forEach((row:any)=>{
                  row[codelist.name] = _this.getCodelistValue(items, row[codelist.name], codelist);
              });
          }
        }
        return jsonData.map((v:any) => filterVal.map((j:any) => v[j]))
    }   


    /**
     * 解析代码表和vlaue，设置items
     *
     * @public
     * @param {any[]} items 代码表数据
     * @param {*} value
     * @returns {*}
     * @memberof Main2
     */
    public getCodelistValue(items: any[], value: any, codelist: any,){
        if(!value){
            return this.$t('codelist.'+codelist.srfkey+'.empty');
        }
        if (items) {
            let result:any = [];
            if(Object.is(codelist.renderMode,"number")){
                items.map((_item: any, index: number)=>{
                    const nValue = parseInt((value as any), 10);
                    const codevalue = _item.value;
                    if((parseInt(codevalue, 10) & nValue) > 0){
                        result.push(_item);
                    } 
                });
            } else if(Object.is(codelist.renderMode,"string")){
                const arrayValue: Array<any> = (value as any).split(codelist.valueSeparator);
                arrayValue.map((value: any, index: number) => {
                    result.push([]);
                    let values: any[] = Object.is(this.$util.typeOf(value), 'number') ? [value] : [...(value as any).split(codelist.valueSeparator)];
                    values.map((val:any ,num: number)=>{
                        const item = this.getItem(items, val, codelist); 
                        if(item){
                          result[index].push(item);
                        } 
                    });
                });
            } else {
                let values: any[] = Object.is(this.$util.typeOf(value), 'number') ? [value] : [...(value as any).split(codelist.valueSeparator)];
                values.map((value:any ,index: number)=>{
                    const item = this.getItem(items, value, codelist); 
                    if(item){
                      result.push(item);
                    } 
                });
            }
            // 设置items
            if(result.length != 0){
              return result.join(codelist.valueSeparator);
            }else{
              return value;
            }
        }
    }

    /**
     * 获取代码项
     *
     * @public
     * @param {any[]} items
     * @param {*} value
     * @returns {*}
     * @memberof Main2
     */
    public getItem(items: any[], value: any, codelist: any): any {
        const arr: Array<any> = items.filter(item => {return item.value == value});
        if (arr.length !== 1) {
            return undefined;
        }
        if(Object.is(codelist.codelistType,'STATIC')){
            return this.$t('codelist.'+codelist.srfkey+'.'+arr[0].value);
        }else{
            return arr[0].text;
        }
    }

    /**
     * 生命周期
     *
     * @memberof Main2
     */
    public created(): void {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof Main2
     */    
    public afterCreated(){
        this.setColState();
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.load(data);
                }
                if (Object.is('remove', action)) {
                    this.remove(data);
                }
                if (Object.is('save', action)) {
                    this.save(data);
                }
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof Main2
     */
    public destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof Main2
     */
    public afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

    /**
     * 获取选中行胡数据
     *
     * @returns {any[]}
     * @memberof Main2
     */
    public getSelection(): any[] {
        return this.selections;
    }

    /**
     * 行双击事件
     *
     * @param {*} $event
     * @returns {void}
     * @memberof Main2
     */
    public rowDBLClick($event: any): void {
        if (!$event || this.actualIsOpenEdit || Object.is(this.gridRowActiveMode,0)) {
            return;
        }
        this.selections = [];
        this.selections.push(JSON.parse(JSON.stringify($event)));

        const refs: any = this.$refs;
        if (refs.multipleTable) {
            refs.multipleTable.clearSelection();
            refs.multipleTable.toggleRowSelection($event);
        }

        this.$emit('rowdblclick', this.selections);
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 复选框数据选中
     *
     * @param {*} $event
     * @returns {void}
     * @memberof  Main2
     */
    public select($event: any): void {
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 复选框数据全部选中
     *
     * @param {*} $event
     * @memberof  Main2
     */
    public selectAll($event: any): void {
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    
    /**
     * 行单击选中
     *
     * @param {*} $event
     * @returns {void}
     * @memberof Main2
     */
    public rowClick($event: any, ifAlways: boolean = false): void {
        if (!ifAlways && (!$event || this.actualIsOpenEdit)) {
            return;
        }
        if(this.stopRowClick) {
            this.stopRowClick = false;
            return;
        }
        if(this.isSingleSelect){
            this.selections = [];
        }
        // 已选中则删除，没选中则添加
        let selectIndex = this.selections.findIndex((item:any)=>{
            return Object.is(item.pfcontract,$event.pfcontract);
        });
        if (Object.is(selectIndex,-1)){
          this.selections.push(JSON.parse(JSON.stringify($event)));
        } else {
          this.selections.splice(selectIndex,1);
        }

        const refs: any = this.$refs;
        if (refs.multipleTable) {
            if(this.isSingleSelect){
                refs.multipleTable.clearSelection();
                refs.multipleTable.setCurrentRow($event);
            }else{
                refs.multipleTable.toggleRowSelection($event); 
            }
        }

        this.$emit('selectionchange', this.selections);
    }


    /**
     * 页面变化
     *
     * @param {*} $event
     * @returns {void}
     * @memberof Main2
     */
    public pageOnChange($event: any): void {
        if (!$event) {
            return;
        }
        if ($event === this.curPage) {
            return;
        }
        this.curPage = $event;
        this.load({});
    }

    /**
     * 分页条数变化
     *
     * @param {*} $event
     * @returns {void}
     * @memberof Main2
     */
    public onPageSizeChange($event: any): void {
        if (!$event) {
            return;
        }
        if ($event === this.limit) {
            return;
        }
        this.limit = $event;
        if (this.curPage === 1) {
            this.load({});
        }
    }

    /**
     * 分页刷新
     *
     * @memberof Main2
     */
    public pageRefresh(): void {
        this.load({});
    }

    /**
     * 排序变化
     *
     * @param {{ column: any, prop: any, order: any }} { column, prop, order }
     * @memberof Main2
     */
    public onSortChange({ column, prop, order }: { column: any, prop: any, order: any }): void {
        const dir = Object.is(order, 'ascending') ? 'asc' : Object.is(order, 'descending') ? 'desc' : '';
        if (Object.is(dir, this.minorSortDir) && Object.is(this.minorSortPSDEF, prop)) {
            return;
        }
        this.minorSortDir = dir;
        this.minorSortPSDEF = prop ? prop : '';
        this.load({});
    }

    /**
     * 表格行选中样式
     *
     * @param {{ row: any, rowIndex: any }} { row, rowIndex }
     * @returns {string}
     * @memberof Main2
     */
    public onRowClassName({ row, rowIndex }: { row: any, rowIndex: any }): string {
        const index = this.selections.findIndex((select: any) => Object.is(select.srfkey, row.srfkey));
        return index !== -1 ? 'grid-row-select' : '';
    }



    /**
     * 界面行为
     *
     * @param {*} row
     * @param {*} tag
     * @param {*} $event
     * @memberof Main2
     */
	public uiAction(row: any, tag: any, $event: any) {
        this.rowClick(row, true);
    }

    /**
     * 设置列状态
     *
     * @memberof Main2
     */
    public setColState() {
		const _data: any = localStorage.getItem('pfcontract_main2_grid');
		if (_data) {
			let columns = JSON.parse(_data);
			columns.forEach((col: any) => {
				let column = this.allColumns.find((item) => Object.is(col.name, item.name));
				if (column) {
					Object.assign(column, col);
				}
			});
		}
    }

    /**
     * 列变化
     *
     * @memberof Main2
     */
    public onColChange() {
        localStorage.setItem('pfcontract_main2_grid', JSON.stringify(this.allColumns));
    }

    /**
     * 获取列状态
     *
     * @param {string} name
     * @returns {boolean}
     * @memberof Main2
     */
    public getColumnState(name: string): boolean {
        let column = this.allColumns.find((col: any) =>
            Object.is(name, col.name)
        );
        return column.show ? true : false;
    }

    /**
     * 表格列是否自适应布局
     *
     * @readonly
     * @type {boolean}
     * @memberof Main2
     */
    get adaptiveState(): boolean {
        return !this.allColumns.find((column: any) => column.show && Object.is(column.util, 'STAR'));
    }

    /**
     * 保存
     *
     * @param {*} $event
     * @returns {void}
     * @memberof Main2
     */
    public save(args: any[], params?: any, $event?: any, xData?: any): void {
        let _this = this;
        let promises:any = [];
        _this.items.forEach((item:any)=>{
            if(!item.rowDataState){
                return;
            } else if(Object.is(item.rowDataState, 'create')){
                if(!this.createAction){
                    this.$Notice.error({ title: '错误', desc: 'PFCONTRACTGridView视图表格createAction参数未配置' });
                    return;
                }
                Object.assign(item,{viewparams:this.viewparams});
                promises.push(this.service.add(this.createAction, JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator));
            }else if(Object.is(item.rowDataState, 'update')){
                if(!this.updateAction){
                    this.$Notice.error({ title: '错误', desc: 'PFCONTRACTGridView视图表格updateAction参数未配置' });
                    return;
                }
                Object.assign(item,{viewparams:this.viewparams});
                if(item.pfcontract){
                    Object.assign(this.context,{pfcontract:item.pfcontract})
                }
                promises.push(this.service.add(this.updateAction,JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator));
            }
        });
        Promise.all(promises).then((response: any) => {
            this.$emit('save', response);
            this.$Notice.success({ title: '', desc: '保存成功!' });
            this.refresh([]);
        }).catch((response: any) => {
            this.$Notice.error({ title: '错误', desc: '系统异常' });
        });
    }


    /**
     * 获取对应行class
     *
     * @param {*} $args row 行数据，rowIndex 行索引
     * @returns {void}
     * @memberof Main2
     */
    public getRowClassName(args:{row: any,rowIndex: number}){
        let isSelected = this.selections.some((item:any)=>{
            return Object.is(item.pfcontract,args.row.pfcontract);
        });
        return isSelected ? "grid-selected-row" : "";
    }
}
</script>

<style lang='less'>
@import './main2-grid.less';
</style>